/*
 * CodeSaveCommand.java
 *
 * Created on 2006년 3월 29일 (수), 오후 4:11
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.qbooks.store.book;

import java.util.*;





import javax.servlet.*;
import javax.servlet.http.*;

import com.zll.framework.model.HashBox;
import com.zll.framework.servlet.Command;
import com.zll.framework.util.StringUtil;
import com.qbooks.common.CommonUtil;





/**
 *
 * @author eastar
 */
public class BookPurchaseCommand implements Command
{

    public String execute(HttpServletRequest  request, HttpServletResponse response)
    throws Exception
    {
    	HashMap result		= new HashMap();
    	HashBox box = new HashBox(request);

    	String memberId		= StringUtil.nvl(request.getSession().getAttribute("session.member_id"));

    	if (memberId.equals("")) {

    		result.put("result", 	"true");
    		result.put("target",	box.target);
    		result.put("action",	"/home/store/login.jsp");
    	}
    	else {
    		StoreDAO dao 		= new StoreDAO();

    		box.put("member_id", memberId);

    		dao.purchaseBook(box);

    		result.put("result", 	"true");
    		result.put("target",	box.target);
    		result.put("action",	"/home/store/successPurchase.jsp");
    	}



    	request.setAttribute("result", result);


    	return "/common/move_view.jsp";
    }
}
